<template>
  <div>
    <h3>{{title}}</h3>
    <el-table :data="list" style="width: 100%">
      <el-table-column v-for="(prop, index) in header" :key="'prop'+index" :prop="prop" :label="prop" />
    </el-table>
    <el-pagination
      v-if="dataSource.length>0"
      v-model:current-page="currentPage"
      v-model:page-size="pageSize"
      :page-sizes="[10, 20, 30, 40]"
      layout="total, sizes, prev, pager, next, jumper"
      :total="dataSource.length"
      @size-change="getList"
      @current-change="getList"
    />
  </div>
</template>

<script name="BasicTable" setup lang="ts">
import { onMounted, ref, toRefs } from "vue"
const prop = defineProps({
  header: {
    type: Array,
    default:()=>[]
  },
  title: {
    type: String,
    default: "",
  },
  dataSource: {
    type: String,
    default:()=>[]
  }
})
const { header, title, dataSource } = toRefs(prop);
const currentPage = ref(1);
const pageSize = ref(10);
const list = ref();

const getList = () => {
  const start = (currentPage.value - 1) * pageSize.value;
  const end = currentPage.value * pageSize.value;
  list.value = dataSource.value.slice(start, end);
}
onMounted(()=>{
  getList();
})
</script>